#include <stdio.h>
#include <LPC2103.H>
#include "enc28j60.h"

#define LED		(1<<13)        //P0.13 LED

#define CS 		(1<<3)
#define reset 	(1<<2)

extern int ENC_main(void);

void uart_int(unsigned char ch)
{
	if(ch==0)
	{
		PINSEL0 |= 0x05;
		PINSEL1 = 0x00;
		//U0LCR = 0x80;  	//SET DLAB
		U0LCR = 0x83;  		//SET DLAB
		U0DLM = 0x00;  		//115200bps @66.35520M
		//U0DLL = 0x24;
		U0DLL = 97;
		U0LCR = 0x03;
	}
}


void spi_int(void)
{
	PINSEL0 |= 0x1500;
	IODIR |= CS;			//P0.7
	S0SPCCR = 0x08;  		//0a 6.6m 0c 5.5m 0e 4.7m
	S0SPCR = 0x20;
}


do_spi(unsigned char dat)
{
	S0SPDR = dat;
	while( 0==(S0SPSR&0x80));
	return(S0SPDR);
}

int main (void) 
{  
	unsigned int ii=0;
	IODIR = 0x04000000|1<<13;
	IODIR |= (1<<9);		//set p0.9 as reset
	IOCLR |= reset;

	while(ii<200)
	{
		ii++;
	}
	
	IOSET|=reset;
	
	while(ii<35535)
	{
		ii++;
	}
	
	uart_int(0);
	spi_int();
	printf("Ready!"	);
	ENC_main();  
}
